home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 4.1 KB | 146 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
-
- import quicktime.*;
- import quicktime.app.time.*;
- import quicktime.io.*;
- import quicktime.std.movies.*;
- import quicktime.std.*;
- import quicktime.std.image.*;
- import quicktime.app.*;
- import quicktime.app.players.*;
- import quicktime.app.display.*;
- /**
- * A simple panel of AWT objects to demonstrate how AWT can be used to control a
- * QuickTime movie.
- */
- public class ControlPanel extends Panel implements Errors, StdQTConstants {
- private String strx;
- //_________________________ CLASS METHODS
- public ControlPanel (Timer ti, Frame m) {
- this.t = ti;
- this.f = m;
-
- GridBagLayout gb = new GridBagLayout();
- setLayout (gb);
- setFont (new Font("Helvetica", Font.BOLD, 10));
-
- GridBagConstraints cons = new GridBagConstraints();
- cons.fill = GridBagConstraints.HORIZONTAL;
- cons.gridheight = 1;
- cons.insets = new Insets (2, 2, 2, 2);
- cons.gridwidth = 2;
- cons.gridy = 0;
- cons.gridx = 0;
- add (rateLabel, cons);
-
- cons.gridx = 2;
- add (rateField, cons);
-
- cons.gridx = 4;
- add (makeMovie, cons);
-
- cons.gridy = 1;
- cons.gridx = 0;
- add (scaleLabel, cons);
-
- cons.gridx = 2;
- add (scaleField, cons);
-
- cons.gridx = 4;
- add (periodLabel, cons);
-
- cons.gridx = 6;
- add (periodField, cons);
-
-
-
- rateField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- strx = new String (event.getActionCommand());
- t.setRate (new Float (strx).floatValue());
-
- }
- });
- scaleField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- String str = new String (event.getActionCommand());
- try {
- t.rescheduleTickle (new Integer (str).intValue(), t.getPeriod());
- } catch (QTException e) {
- e.printStackTrace();
- }
- }
- });
- periodField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- String str = new String (event.getActionCommand());
- try {
- t.rescheduleTickle (t.getScale(), new Integer (str).intValue());
- } catch (QTException e) {
- e.printStackTrace();
- }
- }
- });
- makeMovie.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- try {
- QTCanvas movCanv = new QTCanvas(QTCanvas.kInitialSize, 0.5f, 0.5f);
- f.add ("West", movCanv);
- File fl = QTFactory.findAbsolutePath ("jumps.mov");
- OpenMovieFile movieFile = OpenMovieFile.asRead(new QTFile(fl));
- Movie mov = Movie.fromFile (movieFile);
- t.getTimeBase().setMasterTimeBase(mov.getTimeBase(), null);
- MovieController mc = new MovieController (mov);
- mc.setLooping (true);
- p = new QTPlayer (mc);
- movCanv.setClient (p, true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- QTPlayer p;
- Frame f;
-
- public void setDisplay () throws QTException {
- rateField.setText (Float.toString (t.getRate()));
- scaleField.setText (Integer.toString (t.getScale()));
- periodField.setText (Integer.toString (t.getPeriod()));
- }
-
- //_________________________ INSTANCE VARIABLES
- private Label rateLabel = new Label ("Playback Rate:", Label.RIGHT);
- private TextField rateField = new TextField (8);
-
- private Label scaleLabel = new Label ("Scale:", Label.RIGHT);
- private TextField scaleField = new TextField (8);
-
- private Label periodLabel = new Label ("Period:", Label.RIGHT);
- private TextField periodField = new TextField (8);
-
- private Button makeMovie = new Button ("Make Movie");
- Timer t;
-
- //_________________________ INSTANCE METHODS
- /**
- * @return a Dimension object which defines the minimum size
- */
- public Dimension getMinimumSize() { return new Dimension (0, 80); }
-
- /**
- * @return a Dimension object which defines the preferred size
- */
- public Dimension getPreferredSize() { return getMinimumSize(); }
- }
-